package com.zhouxiaoge.socket.serversocket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/***************************************************
 *                    _ooOoo_                  *   
 *                   o8888888o                 * 佛        
 *                  88'' . ''88                * 祖 
 *                  ( | -_- | )                * 保 
 *                   0\  =  /0                 * 佑 
 *                ____/'---'\____              *    
 *              .'  \\|     |//  '.            * 永 
 *             /  \\|||  :  |||//  \           * 无 
 *            /  _||||| -:- |||||-  \          * BUG
 *            |   | \\\  -  /// |   |          *
 *            | \_|  ''\---/''  |   |          * 阿
 *            \  .-\__  `-`  ___/-. /          * 弥
 *          ___`. .'  /--.--\  `. . __         * 陀
 *       ."" '<  ‘.___\_<|>_/___.’  >'"".      * 佛
 *      | | :  ` - `.;`\ _ /`;.`/ - ` : | |    *
 *      \  \ `-.   \_ __\ /__ _/   .-` /  /    * 
 * ======`-.____`-.___\_____/___.-`____.-'=====*
 * @author 周明阳 mail:gqzmy@outlook.com 时间:2017-12-11 9:30
 */
public class SocketOperate extends Thread {
    private Socket socket;

    public SocketOperate(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream in = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();
            while (true) {
                //读取客户端发送的信息
                String strXML = "";
                byte[] temp = new byte[1024];
                int length = 0;
                while ((length = in.read(temp)) != -1) {
                    strXML = strXML + new String(temp, 0, length);
                }
                System.out.println("客户端发来：" + strXML.toString());
                outputStream.write(strXML.toUpperCase().getBytes());
                outputStream.close();
                in.close();
                break;
            }
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
